package com.xb.dao;

import com.xb.entity.Dept;
import org.springframework.jdbc.core.BeanPropertyRowMapper;

import java.util.List;
import java.util.Map;

public class DeptDao extends BaseDao{

    /**
     * 查询部门信息,包括部门id、部门名称、部门人数
     * @return
     */
    public List<Map<String, Object>> findDeptAll() {
        String sql="SELECT\n" +
                "\td.id deptId,\n" +
                "\td.name deptName,\n" +
                "\tcount( u.dept_id ) deptCount \n" +
                "FROM\n" +
                "\tdept d\n" +
                "\tLEFT OUTER JOIN user u ON d.id = u.dept_id \n" +
                "GROUP BY\n" +
                "\td.id";
        return jdbcTemplate.queryForList(sql);

    }


    /**
     * 查询部门信息
     * @return
     */
    public List<Dept> findAll() {
        String sql="select * from dept";
        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(Dept.class));
    }
}
